package net.example.model.common;


import com.oraycn.omcs.utils.BufferUtils;

import io.netty.buffer.ByteBuf;

/**
 * Created by ZN on 2017/2/8.
 */

public class MessageColor {
    private byte red;
    private byte green;
    private byte blue;
    private byte alpha;

    public byte getAlpha() {
        return alpha;
    }

    public void setAlpha(byte alpha) {
        this.alpha = alpha;
    }

    public byte getRed() {
        return red;
    }

    public void setRed(byte red) {
        this.red = red;
    }

    public byte getGreen() {
        return green;
    }

    public void setGreen(byte green) {
        this.green = green;
    }

    public byte getBlue() {
        return blue;
    }

    public void setBlue(byte blue) {
        this.blue = blue;
    }



    public void deserialize(ByteBuf buffer) throws Exception {
        this.alpha= buffer.readByte();
        this.red = buffer.readByte();
        this.green = buffer.readByte();
        this.blue = buffer.readByte();
    }

    public byte[] serialize() throws Exception {
        ByteBuf body = BufferUtils.newBuffer();
        body.writeByte(this.alpha);
        body.writeByte(this.red);
        body.writeByte(this.green);
        body.writeByte(this.blue);

        byte[] bytes = new byte[body.writerIndex()];
        body.getBytes(0, bytes);
        return bytes;
    }
}
